//[a,b,c,d]=> {a:{b:{c:{d:null}}}}

function toObj(arr) {
    let res = null
    arr.reverse().forEach(item => {
        res = { [item]: res }
    });
    return res
}
let arr = ['a', 'b', 'c', 'd']
console.log(JSON.stringify(toObj(arr)));